package com.echo.util;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by EchoGe on 2016/6/7.
 */
public class TimeUtil {

    public static void main(String[] args){
        String time= secondsToStr(1000);
        String time1=secondsToStr(200);
        String time2=secondsToStr(10000);
        String time3=secondsToStr(10);
        System.out.println(time+"\n"+time1+"\n"+time2+"\n"+time3);
    }

    public static String secondsToStr(int seconds){
        int hours=seconds/3600;
        int minutes=seconds%3600/60;
        int second=seconds%3600%60;
        String str="";
        if(hours<10)
            str+="0";
        str+=hours+":";
        if(minutes<10)
            str+="0";
        str+=minutes+":";
        if(second<10)
            str+="0";
        str+=second;
        return str;
    }

    public static String getTimeStr(Calendar cl){
        Date date=cl.getTime();
        int year=date.getYear();
        int month=date.getMonth();
        int day=date.getDate();
        int hour=date.getHours();
        int minute=date.getMinutes();
        int second=date.getSeconds();
        String time="";
        time+=year;
        if(month<10)
            time+="0";
        time+=month;
        if(day<10)
            time+="0";
        time+=day;
        if(hour<10)
            time+="0";
        time+=hour;
        if(minute<10)
            time+="0";
        time+=minute;
        if(second<10)
            time+="0";
        time+=second;
        return time;
    }
}
